﻿@model SearchModel
@using Nop.Core.Domain.Forums;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{   
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(T("Forum.PageTitle.Search").Text);
    //page class
    Html.AppendPageCssClassParts("html-forum-search-page");
}
<script type="text/javascript">
    $(document).ready(function () {
        toggleAdvancedSearch();
        $('#adv').click(function () {
            toggleAdvancedSearch();
        });
    });
    function toggleAdvancedSearch() {
        if ($('#adv').is(':checked')) {
            $('#advanced-search').show();
        }
        else {
            $('#advanced-search').hide();
        }
    }
</script>
@Html.Action("ForumBreadcrumb")
<div class="page forum-search-page">
    <div class="page-title">
        <h1>@T("Forum.Search")</h1>
    </div>
<div class="page-body">
    @Html.Widget("boards_search_before_searchform")
    <div class="search-input">
        @using (Html.BeginRouteForm("Search", FormMethod.Get))
        {
            <div class="fieldset">
                <div class="form-fields">
                    <div class="basic-search">
                        <div class="inputs">
                            <label>@T("Forum.Search.SearchKeyword")</label>
                            @Html.TextBox("searchterms", null, new {@class = "forum-search-text"})
                        </div>
                        <div class="inputs reversed">
                            @Html.CheckBox("adv", Model.ShowAdvancedSearch)
                            @Html.Label("adv", T("Forum.Search.AdvancedSearch").Text)
                        </div>
                    </div>
                    <div class="advanced-search" id="advanced-search" style="display: none;">
                        <div class="inputs">
                            <label>@T("Forum.Search.SearchInForum")</label>
                            @Html.DropDownList("forumId", new SelectList(Model.ForumList, "Value", "Text", Model.ForumIdSelected))
                        </div>
                        <div class="inputs">
                            <label>@T("Forum.Search.SearchWithin")</label>
                            @Html.DropDownList("within", new SelectList(Model.WithinList, "Value", "Text", Model.WithinSelected))
                        </div>
                        <div class="inputs">
                            <label>@T("Forum.Search.LimitResultsToPrevious")</label>
                            @Html.DropDownList("limitDays", new SelectList(Model.LimitList, "Value", "Text", Model.LimitDaysSelected))
                        </div>
                    </div>
                </div>
            </div>
            <div class="buttons">
                <input type="submit" class="button-1 forum-search-button" value="@T("Forum.SearchButton")"/>
            </div>
        }
    </div>
    @Html.Widget("boards_search_after_searchform")
    <div class="search-error">
        @Model.Error
    </div>
    <div class="search-results">
        @{
            var searchterms = Model.SearchTerms;
            string adv = null;
            string within = null;
            string limitDays = null;
            string forumId = null;

            if (Model.ShowAdvancedSearch)
            {
                adv = "true";
                within = Model.WithinSelected.ToString();
                limitDays = Model.LimitDaysSelected.ToString();
                forumId = Model.ForumIdSelected.ToString();
            }

            var pager = Html.Pager(new PagerModel
            {
                PageSize = Model.TopicPageSize,
                TotalRecords = Model.TopicTotalRecords,
                PageIndex = Model.TopicPageIndex,
                ShowTotalSummary = false,
                RouteActionName = "Search",
                RouteValues = new ForumSearchRouteValues {adv = adv, searchterms = searchterms, forumId = forumId, within = within, limitDays = limitDays},
            });
        }
        @Html.Widget("boards_search_before_results")
        @if (!MvcHtmlString.IsNullOrEmpty(pager))
        {
            <div class="pager upper">
                @pager
            </div>
        }
        @if (Model.NoResultsVisisble)
        {
            <div class="no-result">
                @T("Forum.SearchNoResultsText")
            </div>
        }
        <div class="forums-table-section topic-group">
            @if (Model.SearchResultsVisible)
            {
                <div class="table-wrapper">
                    <table class="forum-table">
                        <colgroup>
                            <col width="1"/>
                            <col/>
                            <col width="1"/>
                            <col width="1"/>
                            <col width="1"/>
                        </colgroup>
                        <thead>
                        <tr>
                            <th class="topic-details" colspan="2">
                                @T("Forum.TopicTitle")
                            </th>
                            <th class="replies">
                                @T("Forum.Replies")
                            </th>
                            <th class="views">
                                @T("Forum.Views")
                            </th>
                            @if (Model.AllowPostVoting)
                            {
                                <th class="votes">
                                    @T("Forum.Votes")
                                </th>
                            }
                            <th class="latest-post">
                                @T("Forum.LatestPost")
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach (var topic in @Model.ForumTopics)
                        {
                            var topicType = "post";
                            var topicText = String.Empty;
                            switch (topic.ForumTopicType)
                            {
                                case ForumTopicType.Normal:
                                    topicType = "post";
                                    break;
                                case ForumTopicType.Sticky:
                                    topicType = "sticky";
                                    topicText = string.Format("[{0}]", T("Forum.Sticky"));
                                    break;
                                case ForumTopicType.Announcement:
                                    topicType = "announcement";
                                    topicText = string.Format("[{0}]", T("Forum.Announcement"));
                                    break;
                                default:
                                    topicType = "post";
                                    break;
                            }
                            <tr>
                                <td class="image">
                                    <div class="@topicType"></div>
                                </td>
                                <td class="topic-details">
                                    <div class="topic-title">
                                        @Html.RouteLink(topic.Subject, "TopicSlug", new {id = topic.Id, slug = topic.SeName})
                                        @if (!String.IsNullOrEmpty(topicText))
                                        {
                                            <span class="topic-type">@topicText</span>
                                        }
                                    </div>
                                    @if (topic.NumPosts > Model.PostsPageSize)
                                    {
                                        <div class="topic-pager">
                                            @Html.ForumTopicSmallPager(topic)
                                        </div>
                                    }
                                    <div class="topic-starter">
                                        @if (topic.CustomerId > 0)
                                        {
                                            <label>@T("Forum.Author"):</label>
                                            if (topic.AllowViewingProfiles)
                                            {
                                                @Html.RouteLink(topic.CustomerName, "CustomerProfile", new {Id = topic.CustomerId})
                                            }
                                            else
                                            {
                                                @topic.CustomerName
                                            }
                                        }
                                    </div>
                                </td>
                                <td class="replies">
                                    @topic.NumReplies
                                </td>
                                <td class="views">
                                    @topic.Views
                                </td>
                                @if (Model.AllowPostVoting)
                                {
                                    <td class="votes">
                                        @topic.Votes
                                    </td>
                                }
                                <td class="latest-post">
                                    @Html.Action("LastPost", new {forumPostId = topic.LastPostId, showTopic = false})
                                </td>
                            </tr>
                        }
                        </tbody>
                    </table>
                </div>
            }
        </div>
        @if (!MvcHtmlString.IsNullOrEmpty(pager))
        {
            <div class="pager lower">
                @pager
            </div>
        }
        @Html.Widget("boards_search_after_results")
    </div>
</div>
</div>
